/**
*      author: Y_Yao
*      created: 2025-03-25 16:54:06
**/

#include<bits/stdc++.h>

#define int LL
using namespace std;
using LL = long long;
const LL LLINF = 9e18;
const int INF = 0x3f3f3f3f;
const int N = 1e5 + 7;
int n,m,q;
vector<string> a;
unordered_map<string,int> mp;
int fa[2 * N];

int find(int s)
{
    return fa[s] == s ? s : fa[s] = find(fa[s]);
}

void solve()
{
    cin >> n >> m >> q;
    string tm;
    for(int i = 1;i <= n;i++)
    {
        cin >> tm;
        mp[tm] = i;
        fa[i] = i;
        fa[i + n] = i + n;
    }
    while(m--)
    {
        int f;
        cin >> f;
        string u,v;
        cin >> u >> v;
        if(f == 1)
        {
            if(find(mp[u]) == find(mp[v] + n) || find(mp[v]) == find(mp[u] + n))
            {
                cout << "NO" << endl;
            }
            else
            {
                cout << "YES" << endl;
                fa[find(mp[u])] = find(mp[v]); 
                fa[find(mp[u] + n)] = find(mp[v] + n); 
            }
        }
        else 
        {
            if(find(mp[u]) == find(mp[v]) || find(mp[v] + n) == find(mp[u] + n))
            {
                cout << "NO" << endl;
            }
            else
            {
                cout << "YES" << endl;
                fa[find(mp[u])] = find(mp[v] + n); 
                fa[find(mp[u] + n)] = find(mp[v]); 
            }
        }

    }
    while(q--)
    {
        string u,v;
        cin >> u >> v;
        if(find(mp[u]) == find(mp[v])) 
        {
            cout << 1 << endl;
        }
        else if(find(mp[u] + n) == find(mp[v] + n))
        {
            cout << 1 << endl;
        }
        else if(find(mp[u] + n) == find(mp[v]))
        {
            cout << 2 << endl;
        }
        else if(find(mp[v] + n) == find(mp[u]))
        {
            cout << 2 << endl;
        }
        else cout << 3 << endl;
    }
    
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    int t = 1;
//   cin >> t;
    while(t--)
    {
        solve();
    }
    return 0;
}
